package com.wondertek.web.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wondertek.common.base.Result;
import com.wondertek.common.util.security.PreAuthorize;
import com.wondertek.service.dto.sys.req.SysLogQueryReq;
import com.wondertek.service.entity.sys.SysLogPo;
import com.wondertek.service.service.sys.ISysLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xqs
 */
@RestController
@RequestMapping("/backend/sys/log")
@Tag(name = "系统日志管理")
public class SysLogController {

    @Resource
    private ISysLogService sysLogService;

    /**
     * 分页查询日志
     * @param sysLogQueryReq /
     * @return /
     */
    @PostMapping("/page")
    @Operation(summary = "分页查询日志")
    @PreAuthorize("@el.check('backend:sys:log:page')")
    public Result<Page<SysLogPo>> page(@RequestBody @Validated SysLogQueryReq sysLogQueryReq){
        return Result.success(sysLogService.page(sysLogQueryReq));
    }


    /**
     * 导出日志
     *
     * @param sysLogQueryReq /
     * @return /
     */
    @PostMapping("/export")
    @Operation(summary = "导出日志")
    public void export(@RequestBody @Validated SysLogQueryReq sysLogQueryReq, HttpServletResponse response){
        sysLogService.export(sysLogQueryReq, response);
    }


}
